$(function () {
    let form = layui.form
    form.verify({
        Pwd: [
            /^[\S]{6,15}$/,
            '密码必须为6-15位非空字符'
        ],
        newPwd: function (value) {
            let v1 = $('[name=oldPwd]').val()
            if (v1 === value) {
                return '新密码和旧密码不能相同!'
            }


        },
        rePwd: function (value) {
            let v2 = $('[name=newPwd]').val()
            if (v2 !== value) {
                return '两次密码输入不一致!'
            }
        }
    })
    // 修改密码
    $('#formPwd').on('submit', function (e) {
        e.preventDefault()
        axios({
            method: 'POST',
            url: '/my/updatepwd',
            data: $(this).serialize()
        }).then(res => {
            if (res.data.status !== 0) {
                return layer.msg(res.data.message)
            }
            layer.msg('恭喜您,修改密码成功!')
            $('#formPwd')[0].reset()
            setTimeout(function () {
                window.parent.location.href = '/login.html'
            }, 2000)
        })
    })
})
